package com.lvyq.myplayer.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import org.jetbrains.anko.runOnUiThread
import org.jetbrains.anko.toast

abstract class BaseFragment: Fragment(){
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        init()
    }


    /**
     * fragment 初始化
     */
  open  protected fun init() {

    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return  initView()
    }

    /**
     * 获取视图view
     */
    abstract fun initView(): View?


    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        initListener()
        initData()
    }

    /**
     * 数据初始化
     */
    open protected fun initData() {
    }

    /**
     * adapter listener
     */
    open protected fun initListener() {
    }

    fun  myToast(msg:String){
        context?.runOnUiThread { toast(msg) }
    }



}